<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>QC管理系统</title>
</head>
<body>
<div style="width: 100%;margin: 5px">
    <form id="QC_form" method="post">
        <div  class="easyui-panel" style="text-align: center" data-options="width:'100%'">
            <div  style="width:1500px">
                <div style="margin-top: 5px;">
                    <input class="easyui-combobox" name="pkOrg" style="width: 180px" data-options="label:'组织',labelWidth:'40',labelAlign:'right',valueField:'pkOrg',textField:'name',url:'/qc/pkOrg'">
                    <input class="easyui-textbox" data-options="label:'供/客',labelWidth:'40',labelAlign:'right'" name="customer" style="width:180px;">
                    <input class="easyui-datebox" id="QC_startDates" name="dates" required="required" style="width:200px" editable="false" prompt="日期必选" data-options="label:'日期范围',labelWidth:'60',labelAlign:'right'">—
                    <input class="easyui-datebox" id="QC_endDates" name="endDates" required="required" style="width:150px" editable="false" prompt="日期必选">
                    <input class="easyui-datetimebox" name="wdate" style="width:200px" data-options="label:'出报告时间',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-datetimebox" name="sdate" style="width:180px" data-options="label:'分发报告时间',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-combobox bmbh" name="bmbh" style="width:180px;" data-options="label:'发现环节',labelWidth:'60',labelAlign:'right'">
                </div>
                <div style="margin-top: 5px">
                    <input class="easyui-textbox" name="remark1" style="width:180px;" data-options="label:'品号',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="remark2" style="width:180px;" data-options="label:'品名',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="repno" style="width:200px;" data-options="label:'报告编号',labelWidth:'60',labelAlign:'right'">—
                    <input class="easyui-textbox" name="repno2" style="width:150px;">
                    <input class="easyui-combobox remark7" name="remark7" style="width:200px;" data-options="label:'不合格类型',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-combobox badlev" name="badlev" style="width:180px" data-options="label:'不合格等级',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-combobox cscomplete" name="cscomplete" style="width:180px;" data-options="label:'措施情况',labelWidth:'60',labelAlign:'right'">
                </div>
                <div style="margin-top: 5px">
                    <input class="easyui-textbox" name="remark5" style="width:180px;" data-options="label:'批号',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="remark3" style="width:180px;" data-options="label:'规格',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="etimes" style="width:200px;" data-options="label:'预计工时',labelWidth:'60',labelAlign:'right'">
                    <input class="easyui-textbox" name="times" style="width:162px;" data-options="label:'实际工时',labelWidth:'60',labelAlign:'right'">
                    <input class="easyui-textbox" name="pfh" style="width:200px;" data-options="label:'配方号',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-textbox" name="smast" style="width:180px;" data-options="label:'处理方法',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-textbox" name="dmast" style="width:180px;" data-options="label:'处理结果',labelWidth:'60',labelAlign:'right'">
                </div>
                <div style="margin-top: 5px">
                    <input class="easyui-textbox" name="remark6" style="width:180px;" data-options="label:'数量',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="remark4" style="width:180px;" data-options="label:'单位',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="resource" style="width:370px;" data-options="label:'主要不良',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-textbox" name="dcaddr" style="width:385px;" data-options="label:'调查链接',labelWidth:'80',labelAlign:'right'">
                    <input class="easyui-textbox" name="dutydepart" style="width:180px;" data-options="label:'责任部门',labelWidth:'60',labelAlign:'right'">
                </div>
                <div style="margin-top: 5px">
                    <input class="easyui-textbox" name="remark" style="width:365px;" data-options="label:'备注',labelWidth:'40',labelAlign:'right'">
                    <input class="easyui-textbox" name="badcode" style="width:371px;" data-options="label:'异常类型(代码)',labelWidth:'100',labelAlign:'right'">
                    <input class="easyui-textbox" name="ljaddr" style="width:385px;" data-options="label:'报告链接',labelWidth:'80',labelAlign:'right'">
                    <a href="#" id="QC_Search" class="easyui-linkbutton"
                       data-options="iconCls:'icon-search'" style="width:120px;margin-left: 60px">查询</a>
                </div>
            </div>
        </div>
<!--        <div id="QC_panel_tools" style="width: 100%;text-align: right">-->

<!--        </div>-->
    </form>
</div>
<div id="QC_table_div" style="height:610px;width: 100%">
<table id="QC_table" class="easyui-datagrid" style="height:610px;width: 100%"
       data-options="toolbar:[{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        newData_QC();
                     }
                    },'-',{
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        Delect_QC()
                    }}]">
    <thead>
    <tr>
        <th data-options="field:'nos',width:100,checkbox:'true',hidden:true">系统编号</th>
<!--        <th data-options="field:'_operate',width:80,align:'center',formatter:formatOper">操作</th>-->
        <th data-options="field:'pkOrg',width:100,align:'center'">组织</th>
        <th data-options="field:'remark1',width:100,align:'center'">品号</th>
        <th data-options="field:'remark2',width:100,align:'center'">品名</th>
        <th data-options="field:'remark3',width:100,align:'center'">规格</th>
        <th data-options="field:'remark4',width:100,align:'center'">单位</th>
        <th data-options="field:'remark5',width:100,align:'center'">批号</th>
        <th data-options="field:'remark6',width:100,align:'center'">数量</th>
        <th data-options="field:'remark7',width:100,align:'center'">不合格类型</th>
        <th data-options="field:'dates',width:100,align:'center'">日期</th>
        <th data-options="field:'pfh',width:100,align:'center'">配方号</th>
        <th data-options="field:'customer',width:100,align:'center'">供/客</th>
        <th data-options="field:'repno',width:100,align:'center'">报告编号</th>
        <th data-options="field:'cscomplete',width:100,align:'center'">措施完成情况</th>
        <th data-options="field:'dcaddr',width:100,align:'center',formatter:querySurvey">调查链接</th>
        <th data-options="field:'ljaddr',width:100,align:'center',formatter:queryCost">报告链接</th>
        <th data-options="field:'bmbh',width:100,align:'center'">发现环节</th>
        <th data-options="field:'resource',width:100,align:'center'">主要不良</th>
        <th data-options="field:'smast',width:100,align:'center'">处理方法</th>
        <th data-options="field:'dmast',width:100,align:'center'">处理结果</th>
        <th data-options="field:'wdate',width:100,align:'center'">出报告时间</th>
        <th data-options="field:'sdate',width:100,align:'center'">分发报告时间</th>
        <th data-options="field:'badlev',width:100,align:'center'">不合格等级</th>
        <th data-options="field:'badcode',width:100,align:'center'">异常类型(代码)</th>
        <th data-options="field:'times',width:100,align:'center'">实际工时</th>
        <th data-options="field:'etimes',width:100,align:'center'">预计工时</th>
        <th data-options="field:'dutydepart',width:100,align:'center'">责任部门</th>
        <th data-options="field:'remark',width:100,align:'center'">备注</th>
    </tr>
    </thead>
</table>
</div>
<!--修改form表单-->
<div id="QC_dlg2" class="easyui-dialog" style="width:1100px;height:auto;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <form id="QC_fm2" method="post">
        <div style="float: left;width: 100%">
            <div style="margin: 10px;">
                <!--        主键id-->
                <input name="nos" type="text" style="display: none">
                <input class="easyui-datebox" id="fm2_dates" name="dates" required="required" editable="false"
                       style="width: 175px" data-options="label:'日期',labelWidth:'40'"
                       prompt="日期必填">
                <input class="easyui-combobox" name="pkOrg" style="width: 190px"
                       data-options="valueField:'pkOrg',label:'组织',labelWidth:'40',textField:'name',url:'/qc/pkOrg'">
                <input class="easyui-textbox" name="customer" style="width:150px;" data-options="label:'供/客',labelWidth:'60'">
                <input class="easyui-textbox" name="repno" style="width:150px;" data-options="label:'报告编号',labelWidth:'70'">
                <input class="easyui-combobox remark7" name="remark7" style="width:230px;" data-options="label:'不合格类型',labelWidth:'80'">
            </div>
            <div style="margin: 10px">
                <input id="QC_form_remark1" class="easyui-textbox" name="remark1" style="width: 175px;" data-options="label:'品号',labelWidth:'40'">
                <input id="QC_form_remark2" class="easyui-textbox" name="remark2" style="width: 190px;" data-options="label:'品名',labelWidth:'40'">
                <input class="easyui-combobox bmbh" name="bmbh" style="width:150px;" data-options="label:'发现环节',labelWidth:'60'">
                <input class="easyui-combobox badlev" name="badlev" style="width:150px;" data-options="label:'不合格等级',labelWidth:'70'">
                <input class="easyui-combobox cscomplete" name="cscomplete" style="width:230px;" data-options="label:'措施完成情况',labelWidth:'80'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="remark5" style="width: 175px;" data-options="label:'批 号',labelWidth:'40'">
                <input id="QC_form_remark3" class="easyui-textbox" name="remark3" style="width: 190px;" data-options="label:'规格',labelWidth:'40'">
                <input class="easyui-textbox" name="dutydepart" style="width:150px;" data-options="label:'责任部门',labelWidth:'60'">
                <input class="easyui-textbox" name="etimes" style="width:150px;" data-options="label:'预计工时',labelWidth:'70'">
                <input class="easyui-datetimebox" name="sdate" style="width:230px;" data-options="label:'分发报告时间',labelWidth:'80'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="remark6" style="width: 175px;" data-options="label:'数量',labelWidth:'40'">
                <input id="QC_form_remark4" class="easyui-textbox" name="remark4" style="width: 190px;" data-options="label:'单位',labelWidth:'40'">
                <input class="easyui-textbox" name="pfh" style="width:150px;" data-options="label:'配方号',labelWidth:'60'">
                <input class="easyui-textbox" name="times" style="width:150px;" data-options="label:'实际工时',labelWidth:'70'">
                <input class="easyui-datetimebox" name="wdate" style="width:230px;" data-options="label:'出报告时间',labelWidth:'80'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="badcode" style="width:91%;" data-options="label:'异常类型(代码)',labelWidth:'100'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="resource" style="width:91%;" data-options="label:'主要不良',labelWidth:'100'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="smast" style="width:91%;" data-options="label:'处理方法',labelWidth:'100'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="dmast" style="width:91%;" data-options="label:'处理结果',labelWidth:'100'">
            </div>
            <div style="margin: 10px">
                <input class="easyui-textbox" name="remark" style="width:91%;" data-options="label:'备注',labelWidth:'100'">
            </div>

            <div style="margin: 10px">
                <label>调查链接</label>
                <input class="easyui-filebox" id="filebox-dcaddr" data-options="buttonText:'选择文件'"
                       style="width: 440px;">
                <input type="text" id="text-dcaddr" name="dcaddr" style="width: 435px;margin-left: 10px"
                       readonly="readonly"><br>
                <label>报告链接</label>
                <input class="easyui-filebox" id="filebox-ljaddr" data-options="buttonText:'选择文件'"
                       style="width: 440px;">
                <input type="text" id="text-ljaddr" name="ljaddr" style="width: 435px;margin-left: 10px"
                       readonly="readonly">
            </div>
            <div style="margin: 10px"><span style="color: #c9302c;size: 15px">提示：请使用IE浏览器上传文件！ 如果文件路径为"C:\fakepath\" , 请设置浏览器开启"文件上传到服务器时包含本地目录路径"</span>
                <a href="https://blog.csdn.net/qq_38961138/article/details/103368990" target="_blank"> 帮助</a>
            </div>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_QC()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="javascript:$('#QC_dlg2').dialog('close')">取消</a>
</div>

<script th:inline="none" type="text/javascript">
//-------------------- 调查链接与报告链接处理 start------------------------------
    //调查链接显示:datagrid中的formatter方法
    function querySurvey(value,row,index){
        return   IsQCServerFile(value);
    }

    //报告链接显示:datagrid中的formatter方法
    function queryCost(value,row,index){
      return   IsQCServerFile(value);
    }

    function IsQCServerFile(value) {
        if (value){
            //暂时只知道这个服务器
            var bol = value.indexOf("\\\\192.168.2.6\\");

            if(bol!=-1){
                //需要：去掉\\192.168.2.6\  服务器中已经配置了映射
                value= value.replace("\\\\192.168.2.6\\","");
            }
            //把路径为'\'的转换为'/',这一步没有转换在传参的时候会去掉'\',加g是代表替换全部，没有加只替换一个
            value= value.replace(/\\/g,"/");

            if (bol!=-1){
                return '<a href="#" onclick="QCOpenFile(\'/ph/'+value+'\')">'+value+'</a>';
            }else {
                return '<a href="#" onclick="QCOpenFile(\'/local/'+value+'\')">'+value+'</a>';
            }

        }
        return "";
    }

    //跳转页面
    function QCOpenFile(val){

        window.open(val);
    }
//-------------------- 调查链接与报告链接处理 end------------------------------

//------插入数据操作输入品号：获取品名、规格、单位--------
    $("#QC_form_remark1").textbox({
        onChange:function (newValue,oldValue) {
            if (newValue !=""){
                $.ajax({
                    url:'/qc/getQCTlevmByRemark1?remark1='+newValue,
                    success:function (data) {

                        if(data.statu==200){
                            $("#QC_form_remark2").textbox("setText",data.data[0].remark2);//品名
                            $("#QC_form_remark2").textbox("setValue",data.data[0].remark2);
                            $("#QC_form_remark3").textbox("setText",data.data[0].remark3);//规格
                            $("#QC_form_remark3").textbox("setValue",data.data[0].remark3);
                            $("#QC_form_remark4").textbox("setText",data.data[0].remark4);//单位
                            $("#QC_form_remark4").textbox("setValue",data.data[0].remark4);
                        }else{
                            $("#QC_form_remark2").textbox("setText","");//品名
                            $("#QC_form_remark2").textbox("setValue","");
                            $("#QC_form_remark3").textbox("setText", "");//规格
                            $("#QC_form_remark3").textbox("setValue", "");
                            $("#QC_form_remark4").textbox("setText", "");//单位
                            $("#QC_form_remark4").textbox("setValue", "");
                            windowsOperation(null,null,data);
                        }
                    },
                    error:function (data) {
                        alert("系统维护中！");
                    }

                })
            }
        }
    })
//------插入数据操作输入品号：获取品名、规格、单位-end-------


    //datagrid过滤form提交查询数据
    function serializeObject(form) {
        var o = {};
        $.each(form.serializeArray(), function (index) {
            if (o[this['name']]) {
                o[this['name']] = o[this['name']] + "," + this['value'];
            } else {
                o[this['name']] = this['value'];
            }
        })
        return o;
    }

//按钮查询事件:初始化表单
    $('#QC_Search').click(function () {
        //判断时间
        if ($('#QC_startDates').val() != "" && $('#QC_endDates').val() != "") {
            var searchForm = $("#QC_form").form();
            $('#QC_table').datagrid({
                onLoadError:function(data){
                    console.log(data)
                  if (data.statu==505){
                      topCommonMessage(data.message)
                  }
                },
                onDblClickRow:function(index, row){ //双击事件弹出修改页面
                    editQC(index);
                },
                queryParams:serializeObject(searchForm), //3月3日，load方法会造成查询两次(load方法查一次，本身的初始化会查询一次)，更换此属性
                rownumbers: 'true',
                pageList:[10,20,50,100,200,500],
                idField: 'nos',
                pagination: 'true',
                url: "/qc/getQCTlevm",
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        newData_QC();
                     }
                    },'-',{
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        Delect_QC()
                    }
                    },'-',{
                        text: '导出当前页面数据',
                        iconCls: 'icon-export-excel',
                        handler: function () {
                            //var start = $('#QC_table').datebox("getValue");
                           // var end = $("#HSDSummary_datebox_end").datebox("getValue");

                            $('#QC_table').datagrid('toExcel', '测试.xls');
                        }
                    },'-',{
                        text: '导出全部数据',
                        iconCls: 'icon-export-excel',
                        handler: function () {
                            //
                            var $eleForm = $("#QC_form");
                            $eleForm.attr("action","/qc/qcExportExcel");
                            //$(document.body).append($eleForm);
                            //提交表单，实现下载
                            $eleForm.submit();

                        }
                    }
                ]

            })
        } else topCommonMessage("请选择日期范围!")
    })

    /*新增信息*/
    function newData_QC() {
        $('#QC_fm2').form('clear');//清除表单
        $('#QC_dlg2').dialog('open').dialog('setTitle', '添加信息');
        url = "/qc/insertQCTlevm";
    }

    //修改，根据选择的行，获取该行所有值，并把值绑定在表单上，url表示form表单的action,后台的执行路径
    function editQC(index) {
       $('#QC_fm2').form('clear');//清除表单
        $('#QC_table').datagrid('selectRow', index);//选中行
        var row = $('#QC_table').datagrid('getSelections');
        if (row.length==1) {
            $('#QC_dlg2').dialog('open').dialog('setTitle', '修改信息');
            $('#QC_fm2').form('load', row[0]);
            url = "/qc/updateQCTlevm";
        }else{
            topCommonMessage("请选择一行进行修改!");
        }
    }
       // console.log(1212121);

    /*保存信息*/
    function save_QC() {
        //报告链接
        $("#text-dcaddr").val($("#filebox-dcaddr").filebox('getValue'));
        //调查链接
        $("#text-ljaddr").val($("#filebox-ljaddr").filebox('getValue'));

        if ($('#fm2_dates').val() != "") {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: url,//url
                data: $('#QC_fm2').serialize(),
                success: function (data) {
                    if (data.statu == 200) {
                        windowsOperation('QC_dlg2', 'QC_table', data);
                    } else if (data.statu == 404) {
                        warnSessionConfirm();
                    } else {
                        $('#QC_dlg2').dialog('close');
                        topCommonMessage(data.message);
                    }
                }
            });
        } else {
            topCommonMessage("请填写日期!")
        }
    }


    /*删除信息*/
    function Delect_QC() {
        var QC_nos = [];
        var row = $('#QC_table').datagrid("getSelections");
        console.log(row);
        for (var i = 0; i < row.length; i++) {
            QC_nos.push(row[i].nos);
        }
        if (QC_nos.length > 0) {
            $.messager.confirm('确认', '您确认想要删除所选信息吗？', function (r) {
                if (r) {
                    $.post("/qc/delectQCTlevm", {
                        nosId: QC_nos,
                    }, function (data) {
                        if (data.statu == 200) {
                            windowsOperation(null, 'QC_table', data);
                            $('#QC_table').datagrid('clearSelections');
                        } else if (data.statu == 404) {
                            setTimeout(northLogout, 2000);
                        } else {
                            topCommonMessage(data.message);
                            $('#QC_table').datagrid('clearSelections');
                        }
                    }, 'json');
                }
            });
        } else {
            topCommonMessage("请选择要删除的信息！")
        }
    }

    $('.remark7').combobox({
        url: '/qc/getFail',
        valueField: 'doccontent',
        textField: 'doccontent'
    });
    $('.cscomplete').combobox({
        url: '/qc/getMeasure',
        valueField: 'doccontent',
        textField: 'doccontent'
    });
    $('.bmbh').combobox({
        url: '/qc/getLink',
        valueField: 'doccontent',
        textField: 'doccontent'
    });
    $('.badlev').combobox({
        url: '/qc/getFailGrades',
        valueField: 'doccontent',
        textField: 'doccontent'
    });
</script>
</body>
</html>